Skip to content

FEAT: Generalize Colloquial Wordswap Attack Converter #1348

Merged
romanlutz merged 12 commits intoAzure:mainfrom
taherakolawala:generalize-colloquial-wordswapper
Feb 27, 2026
Merged

FEAT: Generalize Colloquial Wordswap Attack Converter #1348
romanlutz merged 12 commits intoAzure:mainfrom
taherakolawala:generalize-colloquial-wordswapper

Conversation

@taherakolawala
Copy link
Contributor

@taherakolawala taherakolawala commented Feb 4, 2026

Description

In accordance with the Issue #418 the converter in colloquial_wordswap_converter.py has been generalized to use different versions of colloquial word swaps.

A new directory has been created in pyrit/datasets/prompt_converters called colloquial_wordswaps. This directory contains the original default Singaporean word substitutions as wells as a few different regional colloquial word swap YAML examples. The ColloquialWordSwapConverter class now accepts a new parameter called wordswap_path during initialization. It defaults to singaporean.yaml however the argument can be filled with any YAML file located in the colloquial_wordswaps directory mentioned before.

In the same vein, if you want to add a new set of word substitutions, all you need to do is create a new YAML file in the same format as any of the others and add it to the pyrit/datasets/prompt_converters/colloquial_wordswaps directory. Here is an example of how a YAML file must be formatted:

word: ['alternative1', 'alternative2', 'alternative3']
word2: ['alt1', 'alt2', 'alt3']

The following is an example initialization of the converter with a non-default wordswapper YAML:

converter = ColloquialWordswapConverter(deterministic=True, wordswap_path=filipino.yaml)
# converting the prompt
result = await converter.convert_async('This is my father')
print(result)
# output: This is my papa

People of whom this PR may be of interest to: @eugeniavkim @romanlutz
Closes #418

Tests and Documentation

  • Edited 2 preexisting tests in test_colloquial_wordswap_converter.py for the generalizable wordswap converter.
  • Added 1 new test in test_colloquial_wordswap_converter.py for checking multiple word custom word swapper conversions.
  • All tests pass : uv run pytest tests/unit/converter/test_colloquial_wordswap_converter.py

@taherakolawala
Copy link
Contributor Author

@microsoft-github-policy-service agree

Copy link
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I am personally not convinced Singaporean should be the default BUT that's what we put in the issue description and it means current users won't be experiencing a breaking change. We may update that in the future, of course. Thanks a ton!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Generalizes ColloquialWordswapConverter to load colloquial word-substitution mappings from YAML files (with several new regional examples) while retaining support for direct in-code substitution dictionaries.

Changes:

  • Add wordswap_path option to load substitutions from YAML under pyrit/datasets/prompt_converters/colloquial_wordswaps/ (defaulting to singaporean.yaml).
  • Add new colloquial wordswap YAML datasets (Singaporean + multiple regional examples).
  • Update and expand unit tests to cover YAML-based wordswaps and constructor argument conflicts.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
pyrit/prompt_converter/colloquial_wordswap_converter.py Loads substitutions from YAML via wordswap_path, adds conflict validation, and keeps custom-dict support.
tests/unit/converter/test_colloquial_wordswap_converter.py Updates tests for YAML-based swaps and adds new scenarios/constructor validation tests.
pyrit/datasets/prompt_converters/colloquial_wordswaps/singaporean.yaml Moves prior default substitutions into a dataset file.
pyrit/datasets/prompt_converters/colloquial_wordswaps/filipino.yaml Adds Filipino example substitutions.
pyrit/datasets/prompt_converters/colloquial_wordswaps/indian.yaml Adds Indian example substitutions.
pyrit/datasets/prompt_converters/colloquial_wordswaps/southern_american.yaml Adds Southern American example substitutions.
pyrit/datasets/prompt_converters/colloquial_wordswaps/multicultural_london.yaml Adds Multicultural London example substitutions.

romanlutz and others added 6 commits February 25, 2026 06:32
… files

- Add wordswap_path parameter to load substitutions from YAML files
- Keep custom_substitutions for backward compatibility
- Add YAML files: singaporean, filipino, indian, multicultural_london, southern_american
- Move hardcoded substitutions to singaporean.yaml (remains the default)
- Use CONVERTER_SEED_PROMPT_PATH for consistent path handling
- Make all __init__ params keyword-only for consistency with other converters
- Add input validation: YAML format, value types, mutual exclusion of params
- Catch yaml.YAMLError and re-raise as ValueError with file context
- Include wordswap_path in component identifier for proper tracking
- Add tests for YAML paths, error paths, and custom dict substitutions

Closes Azure#418

Co-authored-by: taherakolawala <181370151+taherakolawala@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…om_substitutions

- Keep deterministic as positional arg (reverting keyword-only change)
- Empty custom_substitutions={} falls through to defaults as before
- Add test for empty custom_substitutions behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Positional usage emits FutureWarning with migration guidance
- Keyword usage works without warning
- Add test for deprecation warning

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify FutureWarning is only emitted for positional usage, not keyword.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
romanlutz and others added 2 commits February 26, 2026 05:42
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz merged commit 07fd38b into Azure:main Feb 27, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FEAT: Generalize Colloquial Wordswap Attack Converter

3 participants